using System;
using System.Text;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using Framework;

namespace SchemaMonitor
{
    //Table-Mapping Class (Customisable half)
    public partial class CLabel_OneToOne
    {
        #region Constants
        #endregion

        #region Constructors (Public)
        //Default Connection String
        public CLabel_OneToOne() : base() {}

        //Alternative Connection String
        public CLabel_OneToOne(CDataSrc dataSrc) : base(dataSrc) {}

        //Hidden  (UI code should use cache instead)
        protected internal CLabel_OneToOne(Guid labelGuid, int labelTypeId ) : base(labelGuid, labelTypeId) {}
        protected internal CLabel_OneToOne(CDataSrc dataSrc, Guid labelGuid, int labelTypeId ) : base(dataSrc, labelGuid, labelTypeId) {}
        protected internal CLabel_OneToOne(CDataSrc dataSrc, Guid labelGuid, int labelTypeId , IDbTransaction txOrNull) : base(dataSrc, labelGuid, labelTypeId, txOrNull) { }
        #endregion

        #region Default Values
        protected override void InitValues_Custom()
        {
            //_sampleDateCreated = DateTime.Now;
            //_sampleSortOrder   = 0;
        }
		#endregion

		#region Default Connection String
		protected override CDataSrc DefaultDataSrc() { return CConfig.Photos; } //CDataSrc.Default;  }
		#endregion

		#region Properties - Relationships
		//Relationships - Foriegn Keys (e.g parent)
		public CMetaTag   MetaTag   { get { return CMetaTag.Cache.GetById(  this.LabelTagId);  } }
		public CPhotoHash PhotoHash { get { return CPhotoHash.Cache.GetById(this.LabelGuid);   } }
		public CTagType   TagType   { get { return CTagType.Cache.GetById(  this.LabelTypeId); } }

		//Relationships - Collections (e.g. children)
		#endregion

		#region Properties - Customisation
		//Derived/ReadOnly (e.g. xml classes, presentation logic)
		#endregion

		#region Save/Delete Overrides
		public override void Save(IDbTransaction txOrNull)
		{
			if (!TagType.TagIsOneToOne)
				throw new Exception("Wrong type of Label");
			base.Save(txOrNull);
		}
		//Can Override base.Save/Delete (e.g. Cascade deletes, or insert related records)
		#endregion

		#region Custom Database Queries
		//(Not normally required for cached classes, use list class for searching etc)
		//For Stored Procs can use: MakeList (matching schema), or DataSrc.ExecuteDataset (reports etc)
		//For Dynamic sql, can use: SelectSum, SelectDistinct, SelectCount, SelectWhere (inherited methods)
		#endregion



		#region Caching Details
		//Cache Key
		internal static string CACHE_KEY = typeof(CLabel_OneToOne).ToString();    //TABLE_NAME

        //Cache data
        private static CLabel_OneToOneList LoadCache()
        {
            return new CLabel_OneToOne().SelectAll();
        }
        //Cache Timeout
        private static void SetCache(CLabel_OneToOneList value)
        {
            if (null != value) 
                value.Sort(); 
            CCache.Set(CACHE_KEY, value);    //Optional parameter can override timeout (otherwise uses config-settings, which default to 3hrs)
        }
        //Helper Method
        private CLabel_OneToOne CacheGetById(CLabel_OneToOneList list)
        {
            return list.GetById(this.LabelGuid, this.LabelTypeId);
        }
        #endregion

        #region Cloning
        public CLabel_OneToOne Clone(CDataSrc target, IDbTransaction txOrNull) //, int parentId)
        {
            //Shallow copy: Copies the immediate record, excluding autogenerated Pks
            CLabel_OneToOne copy = new CLabel_OneToOne(this, target);

            //Deep Copy - Child Entities: Cloned children must reference their cloned parent
            //copy.SampleParentId = parentId;

            copy.Save(txOrNull);

            //Deep Copy - Parent Entities: Cloned parents also clone their child collections
            //this.Children.Clone(target, txOrNull, copy.LabelGuid);

            return copy;
        }
        #endregion

        #region ToXml
        protected override void ToXml_Custom(System.Xml.XmlWriter w)
        {
            //Store(w, "Example", this.Example)
        }
        #endregion
    }
}
